<!documentTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>用户注册</title>
		<script src="../js/mui.min.js"></script>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<style>
			.chart {
				height: 200px;
				margin: 0px;
				padding: 0px;
			}
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">用户注册</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>用户名</label>
				<input type="text" class="mui-input-clear" id="username" placeholder="请输入用户名">
				</div>
				<div class="mui-input-row">
					<label>密码</label>
					<input type="password" class="mui-input-password" id="password" placeholder="请输入密码">
				</div>
				<div class="mui-input-row">
					<label>性别</label>
					<div>
					<div class="mui-radio" style="float: left;"><label>男</label><input id="male" class="gender" name="gender" type="radio"></div>
					<div class="mui-radio" style="float: left;"><label>女</label><input id="female" class="gender" name="gender" type="radio"></div>
					</div>
				</div>
				<div class="mui-input-row">
					<label>城市</label>
				<input type="text" class="mui-input-clear" id="city" placeholder="请输入城市">
				</div>
				<div class="mui-input-row">
					<label>省份</label>
				<input type="text" class="mui-input-clear" id="province" placeholder="请输入省份">
				</div>
				<div class="mui-input-row">
					<label>电话</label>
				<input type="text" class="mui-input-clear" id="userTel" placeholder="请输入联系电话">
				</div>
				<div class="mui-button-row">
					<button type="button" onclick="signUpSubmit();" class="mui-btn mui-btn-primary" >确认</button>
					<button type="button" onclick="cancel();" class="mui-btn mui-btn-danger" >取消</button>
				</div>
			</form>
			<div style="height:44px;"></div>
		</div>
		
		<script>
			mui.init();
			
			function signUpSubmit(){
				var username = document.getElementById('username').value;
				var password = document.getElementById('password').value;
				var gender = 'unknown';
				var city = document.getElementById('city').value;
				var province = document.getElementById('province').value;
				var country = 'none';
				var userTel = document.getElementById('userTel').value;
				if(document.getElementById("male").checked)
				{
					gender = '1'
					//alert("男");
				}
							 
				if(document.getElementById("female").checked)
				{
					gender = '0'
					//alert("女");
				}
				if(username == '' || password == '' || gender == '' || city == '' || province == '' || country == '' || userTel == ''){
					mui.toast('请完成表单以完成注册');
					return;
				}
				//alert('u:'+username+','+'p:'+password)
				var url = localStorage.getItem('remoteAddress') + '/api/userSignUp';
				mui.post(url,{
					userName: username,
					password: password,
					gender: gender,
					city: city,
					province: province,
					country: country,
					userTel: userTel
				},function(data){
					var data = data.data;
					//服务器返回响应，根据响应结果，分析是否登录成功；
					var signUpSuccess = data.signUpSuccess;
					//alert(signUpSuccess);
					if(signUpSuccess == '1'){
						mui.toast('注册成功');
						plus.webview.close('signUpPage');
						var loginPage = plus.webview.open('loginPage.html', 'loginPage', {}, 'slide-in-right', 200);
					}else{
						mui.toast('注册失败，网络错误');
						plus.webview.close('signUpPage');
					}
				},'json'
				);
			}
			
			function cancel(){
				plus.webview.close('signUpPage');
			}
			
		</script>
	</body>
</html>
